package com.radon.api;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.radon.feign.ApiFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Feigin服务消费者
 */
@RestController
public class ConsumptionFeiginApi {

    @Autowired
    private ApiFeign apiFeign;
    //服务降级处理(现在是注解实现，也可以使用实现ApiFeign接口完成降级并且写上注释@FeignClient(value="app-producer",fallback = ConsumerFallback.class))
    @HystrixCommand(fallbackMethod = "getFeignConsumptionFallback")//HystrixCommand默认开启线程池隔离方式、开启服务降级和服务熔断机制，fallbackMethod作用是服务降级
    @RequestMapping("getFeignConsumption")
    public String getFeignConsumption(){
        System.out.println("orderToUserInfo:" + "当前线程池名称:" + Thread.currentThread().getName());
        return apiFeign.getProvision();
    }
    @RequestMapping("getFeignConsumptionFallback")
    public String getFeignConsumptionFallback() {
        return "系统错误!!!!";
    }

}
